package ace.module.account.core.impl.manager.biz;

import ace.cmp.json.api.JsonService;
import ace.module.account.core.impl.dao.entity.IamApplicationConfig;
import lombok.AllArgsConstructor;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Component;

/**
 * .
 * @author Caspar
 *
 */
@AllArgsConstructor
@Component
public class IamApplicationConfigBiz {

  private final JsonService jsonService;

  public String convertToJson(Object config) {
    return this.jsonService.toJson(config);
  }


  public <T> T convertToObject(IamApplicationConfig source, Class<T> cls) {
    if (source == null) {
      return null;
    }
    if (StringUtils.isEmpty(source.getConfig())) {
      return null;
    }
    return jsonService.toObject(source.getConfig(), cls);
  }
}
